// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

import java.sql.*;
import java.util.ResourceBundle;
import org.apache.log4j.Logger;

// Referenced classes of package com.unlimax.app.kerneos:
//            DBObject, MainApp

public class CSVObject {

	public CSVObject() {
	}

	public String getCUSTHeader() {
		StringBuffer stringbuffer = new StringBuffer();
		stringbuffer
				.append("CUSTOMER_CODE;CUSTOMER_NAME;MARKET_SEGMENT;DELIVERY_COUNTRY_CODE;LOGISTIC_DEPARTMENT;SUBSIDIARY_CODE;SUBSIDIARY_BUYER_CODE;LATIN_NAME\r\n");
		return stringbuffer.toString();
	}

	public String getSIHeader() {
		StringBuffer stringbuffer = new StringBuffer();
		stringbuffer
				.append("YEAR;MONTH;INVOICED_CUSTOMER_CODE;PRODUCTION_SITE;DISPATCH_SITE;CLINKER_SITE;INCOTERM;PRODUCT_CODE;PACKING_CODE;QUANTITY;TURNOVER_TRA;CURRENCY_TRA;TURNOVER_SUB;CURRENCY_SUB\r\n");
		return stringbuffer.toString();
	}

	public String getCUSTDetails(String s) {
		StringBuffer stringbuffer = new StringBuffer();
		String s1 = MainApp.bundle.getString("jdbc.url");
		String s2 = MainApp.bundle.getString("jdbc.username");
		String s3 = MainApp.bundle.getString("jdbc.password");
		String s4 = (new StringBuilder())
				.append("SELECT CUST_CODE,NAME,CMMNT FROM ").append(s)
				.append("_CUST WHERE STATUS = 0").toString();
		Object obj = null;
		Object obj1 = null;
		Object obj2 = null;
		Object obj3 = null;
		Object obj4 = null;
		Object obj5 = null;
		Object obj6 = null;
		Object obj7 = null;
		DBObject dbobject = new DBObject();
		try {
			Class.forName(MainApp.bundle.getString("jdbc.driver"));
			Connection connection = DriverManager.getConnection(s1, s2, s3);
			Statement statement = connection.createStatement();
			String s5;
			String s6;
			String s7;
			String s8;
			String s9;
			String s10;
			String s11;
			String s12;
			ResultSet resultset;
			for (resultset = statement.executeQuery(s4); resultset.next(); stringbuffer
					.append((new StringBuilder()).append(s5).append(";")
							.append(s6).append(";").append(s7).append(";")
							.append(s8).append(";").append(s9).append(";")
							.append(s10).append(";").append(s11).append(";")
							.append(s12).append("\r\n").toString())) {
				s5 = resultset.getString("CUST_CODE").trim();
				s6 = resultset.getString("NAME").trim();
				s7 = dbobject.getMarketSegment(s, s5).trim();
				s8 = dbobject.getDeliveryCountry(s, s5).trim();
				s9 = dbobject.getLogisticDepartment(s, s5).trim();
				s10 = dbobject.getSubsidiary(s).trim();
				s11 = dbobject.getSubsidiaryBuyerCode(s, s5).trim();
				if (resultset.getString("CMMNT") != null)
					s12 = resultset.getString("CMMNT").trim();
				else
					s12 = "";
			}

			resultset.close();
			statement.close();
			connection.close();
		} catch (Exception exception) {
			MainApp.logger.error(exception.getMessage());
		}
		return stringbuffer.toString();
	}

	public String getSIDetails(String s, String s1, String s2) {
		StringBuffer stringbuffer = new StringBuffer();
		String s3 = MainApp.bundle.getString("jdbc.url");
		String s4 = MainApp.bundle.getString("jdbc.username");
		String s5 = MainApp.bundle.getString("jdbc.password");
		String s6 = (new StringBuilder())
				.append("SELECT SIL.SI_ID, SIL.SIL_NUM,SIL.ITEM_CODE,SILSOL.QTY,SIL.INV_POSTING_DATETIME,SILSOL.SO_TXN_REF,SO.SALES_DEFN_CODE FROM ")
				.append(s)
				.append("_SIL SIL, ")
				.append(s)
				.append("_SIL_SOL SILSOL, ")
				.append(s)
				.append("_SO SO WHERE INV_POSTING_DATETIME BETWEEN '")
				.append(s1)
				.append("' AND '")
				.append(s2)
				.append("' AND SIL.SI_ID = SILSOL.SI_ID AND SIL.SIL_NUM = SILSOL.SIL_NUM AND SILSOL.SO_TXN_REF = SO.SO_TXN_REF AND SO.SALES_DEFN_CODE IN (")
				.append(MainApp.bundle.getString((new StringBuilder())
						.append(s).append(".type").toString())).append(")")
				.toString();
		Integer integer = Integer.valueOf(0);
		Integer integer3 = Integer.valueOf(0);
		Object obj = null;
		Object obj1 = null;
		Object obj2 = null;
		Object obj3 = null;
		Object obj4 = null;
		Object obj5 = null;
		Object obj6 = null;
		Object obj7 = null;
		Object obj8 = null;
		Object obj9 = null;
		Object obj10 = null;
		Object obj11 = null;
		Object obj12 = null;
		Object obj13 = null;
		Integer integer6 = Integer.valueOf(0);
		Integer integer7 = Integer.valueOf(0);
		Integer integer8 = Integer.valueOf(0);
		DBObject dbobject = new DBObject();
		try {
			Class.forName(MainApp.bundle.getString("jdbc.driver"));
			Connection connection = DriverManager.getConnection(s3, s4, s5);
			Statement statement = connection.createStatement();
			Integer integer1;
			Integer integer4;
			String s7;
			String s9;
			String s11;
			String s13;
			String s15;
			String s17;
			String s19;
			String s21;
			String s23;
			String s25;
			String s27;
			String s29;
			ResultSet resultset;
			for (resultset = statement.executeQuery(s6); resultset.next(); stringbuffer
					.append((new StringBuilder()).append(integer1).append(";")
							.append(integer4).append(";").append(s7)
							.append(";").append(s9).append(";").append(s11)
							.append(";").append(s13).append(";").append(s15)
							.append(";").append(s17).append(";").append(s19)
							.append(";").append(s21).append(";").append(s23)
							.append(";").append(s25).append(";").append(s27)
							.append(";").append(s29).append("\r\n").toString())) {
				String s33 = resultset.getString("SALES_DEFN_CODE").trim();
				String s31 = resultset.getString("SO_TXN_REF");
				integer6 = Integer.valueOf(resultset.getInt("SI_ID"));
				integer7 = Integer.valueOf(resultset.getInt("SIL_NUM"));
				integer1 = Integer.valueOf(Integer.parseInt(resultset
						.getString("INV_POSTING_DATETIME").substring(0, 4)));
				integer4 = Integer.valueOf(Integer.parseInt(resultset
						.getString("INV_POSTING_DATETIME").substring(5, 7)));
				s7 = dbobject.getInvoicedCustomer(s, s31);
				s9 = dbobject.getProductionSite(s);
				s11 = dbobject.getDispatchSite(s);
				s13 = dbobject.getClinkerSite(s);
				s15 = dbobject.getIncoterm(s, s33, integer6, integer7);
				s17 = resultset.getString("ITEM_CODE").trim();
				s19 = dbobject.getPackingCode(s, s17);
				s25 = "";
				s29 = dbobject.getBaseCurrency(s, integer6, integer7);
				if (s.equals("ZGW"))
					s21 = (new Double(resultset.getDouble("QTY"))).toString()
							.replace(".", ",");
				else
					s21 = dbobject.getQuantity(s, integer6, integer7)
							.toString().replace(".", ",");
				s23 = "";
				s27 = dbobject.getBaseAmount(s, integer6, integer7).toString()
						.replace(".", ",");
			}

			resultset.close();
			statement.close();
			connection.close();
		} catch (Exception exception) {
			MainApp.logger.error(exception.getMessage());
		}
		s6 = (new StringBuilder())
				.append("SELECT SOL.SO_TXN_REF, SOL.SOL_NUM, SOL.ITEM_CODE, SOL.DEMAND_QTY, SO.SALES_DEFN_CODE,SOL.ORDER_DATETIME FROM ")
				.append(s)
				.append("_SOL SOL, ")
				.append(s)
				.append("_SO SO WHERE SOL.SO_TXN_REF = SO.SO_TXN_REF AND SOL.STATUS = 3 AND SOL.ORDER_DATETIME BETWEEN  '")
				.append(s1).append("' AND '").append(s2)
				.append("' AND SO.SALES_DEFN_CODE IN (")
				.append(MainApp.bundle.getString("return.type")).append(")")
				.toString();
		try {
			Class.forName(MainApp.bundle.getString("jdbc.driver"));
			Connection connection1 = DriverManager.getConnection(s3, s4, s5);
			Statement statement1 = connection1.createStatement();
			Integer integer2;
			Integer integer5;
			String s8;
			String s10;
			String s12;
			String s14;
			String s16;
			String s18;
			String s20;
			String s22;
			String s24;
			String s26;
			String s28;
			String s30;
			ResultSet resultset1;
			for (resultset1 = statement1.executeQuery(s6); resultset1.next(); stringbuffer
					.append((new StringBuilder()).append(integer2).append(";")
							.append(integer5).append(";").append(s8)
							.append(";").append(s10).append(";").append(s12)
							.append(";").append(s14).append(";").append(s16)
							.append(";").append(s18).append(";").append(s20)
							.append(";").append(s22).append(";").append(s24)
							.append(";").append(s26).append(";").append(s28)
							.append(";").append(s30).append("\r\n").toString())) {
				String s34 = resultset1.getString("SALES_DEFN_CODE").trim();
				String s32 = resultset1.getString("SO_TXN_REF");
				Integer integer9 = Integer
						.valueOf(resultset1.getInt("SOL_NUM"));
				integer2 = Integer.valueOf(Integer.parseInt(resultset1
						.getString("ORDER_DATETIME").substring(0, 4)));
				integer5 = Integer.valueOf(Integer.parseInt(resultset1
						.getString("ORDER_DATETIME").substring(5, 7)));
				s8 = dbobject.getInvoicedCustomer(s, s32);
				s10 = dbobject.getProductionSite(s);
				s12 = dbobject.getDispatchSite(s);
				s14 = dbobject.getClinkerSite(s);
				s16 = dbobject.getCRIncoterm(s, s34, s32, integer9);
				s18 = resultset1.getString("ITEM_CODE").trim();
				s20 = dbobject.getPackingCode(s, s18);
				s26 = "";
				s30 = dbobject.getCRBaseCurrency(s, s32, integer9);
				if (s.equals("ZGW"))
					s22 = (new Double(resultset1.getDouble("QTY"))).toString()
							.replace(".", ",");
				else
					s22 = dbobject.getQuantity(s, integer6, integer7)
							.toString().replace(".", ",");
				s24 = "";
				if (s.equals("ZGW")) {
					Double double1 = Double.valueOf(dbobject.getBaseAmount(s,
							integer6, integer7).doubleValue()
							- dbobject.getFreightAmount(s, integer6, integer7)
									.doubleValue());
					s28 = double1.toString().replace(".", ",");
				} else {
					s28 = dbobject.getBaseAmount(s, integer6, integer7)
							.toString().replace(".", ",");
				}
			}

			resultset1.close();
			statement1.close();
			connection1.close();
		} catch (Exception exception1) {
			MainApp.logger.error(exception1.getMessage());
		}
		return stringbuffer.toString();
	}

	public String toSBC(String s) {
		char ac[] = s.toCharArray();
		for (int i = 0; i < ac.length; i++) {
			if (ac[i] == ' ') {
				ac[i] = '\u3000';
				continue;
			}
			if (ac[i] < '\177')
				ac[i] = (char) (ac[i] + 65248);
		}

		return new String(ac);
	}
}
